#include <clang/Frontend/FrontendActions.h>
#include <clang/Tooling/CommonOptionsParser.h>
#include <clang/Tooling/Tooling.h>
#include <llvm/Support/CommandLine.h>

#include "goto-checker.hpp"

using namespace clang::tooling;
using namespace clang::ast_matchers;

int main(int argc, const char **argv) {
	CommonOptionsParser OptionsParser(argc, argv);
	ClangTool Tool(
		OptionsParser.GetCompilations(),
		OptionsParser.GetSourcePathList()
	);
	MatchFinder mf;
	GotoChecker handler;

	mf.addMatcher(functionDecl(isDefinition()).bind("func"), &handler);
	mf.addMatcher(gotoStmt().bind("goto"), &handler);
	mf.addMatcher(labelStmt().bind("label"), &handler);
	return Tool.run(newFrontendActionFactory(&mf));
}
